<template>
  <el-container class="admin-layout">
    <!-- 侧边栏 -->
    <el-aside width="200px" class="admin-aside">
      <div class="logo">
        <h2>实验室管理系统</h2>
      </div>
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical"
        background-color="#304156"
        text-color="#fff"
        active-text-color="#409EFF"
        @select="handleMenuSelect"
      >
        <el-menu-item index="/attendance">
          <el-icon><Calendar /></el-icon>
          <span>考勤记录管理</span>
        </el-menu-item>
        
        <el-menu-item index="/leave">
          <el-icon><Document /></el-icon>
          <span>请假管理</span>
        </el-menu-item>
        
        <el-menu-item index="/weekly">
          <el-icon><Notebook /></el-icon>
          <span>周报管理</span>
        </el-menu-item>
        
        <el-menu-item index="/profile">
          <el-icon><User /></el-icon>
          <span>基本信息管理</span>
        </el-menu-item>

        <el-menu-item index="/adminManagement">
          <el-icon><User /></el-icon>
          <span>个人信息管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 主体内容区 -->
    <el-container>
      <!-- Header -->
      <el-header>
        <div class="header-right">
          <span class="username">管理员</span>
          <el-dropdown>
            <el-icon class="user-icon"><Setting /></el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <!-- Main Content -->
      <el-main>
        <!-- 动态显示组件 -->
        <component :is="currentComponent" />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { ref, computed } from 'vue'
import { Calendar, Document, Notebook, User, Setting } from '@element-plus/icons-vue'
import AttendanceList from './AttendanceList.vue'
import LeaveManagement from './LeaveManagement.vue'
import WeeklyList from './WeeklyList.vue'
import UserList from './UserList.vue'
import AdminManagement from './AdminManagement.vue'

export default {
  name: 'AdminLayout',
  components: {
    Calendar,
    Document,
    Notebook,
    User,
    Setting,
    AttendanceList,
    LeaveManagement,
    WeeklyList,
    UserList,
    AdminManagement
  },
  setup() {
    const activeMenu = ref('/attendance')  // 初始选中考勤记录管理
    
    // 根据 activeMenu 选择当前显示的组件
    const currentComponent = computed(() => {
      const components = {
        '/attendance': AttendanceList,
        '/leave': LeaveManagement,
        '/weekly': WeeklyList,
        '/profile': UserList,
        '/adminManagement': AdminManagement
      }
      return components[activeMenu.value]  // 返回对应的组件
    })

    // 菜单项点击时更新 activeMenu
    const handleMenuSelect = (index) => {
      activeMenu.value = index  // 更新 activeMenu 为选中的菜单项的 index
    }

    return {
      activeMenu,
      currentComponent,
      handleMenuSelect
    }
  }
}
</script>

<style scoped>
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#app {
  height: 100%;
}

.admin-layout {
  height: 100%;
  display: flex;
  flex-direction: row; /* 使用行方向，保证左侧和右侧水平排列 */
}

.el-container {
  height: 100%;
  display: flex;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
  height: 100%;
  overflow-y: auto;
  flex-grow: 1;  /* 使右侧区域自适应剩余宽度 */
}

.el-aside {
  background-color: #304156;
  color: #fff;
  height: 100%;
  padding-top: 10px;
}

.el-menu {
  width: 100%;
  border-right: none;
}

.el-menu-item {
  padding: 10px 20px;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2b2f3a;
}

.logo h2 {
  color: #fff;
  margin: 0;
  font-size: 18px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.username {
  font-size: 14px;
  color: #606266;
}

.user-icon {
  font-size: 20px;
  color: #606266;
  cursor: pointer;
}
</style>
